// 定义变量，用于记录当前显示的图片的索引值
var currentIndex = 0;
// 获取所有的图片元素
var images = document.getElementsByClassName('image');

// 定义一个函数，用于切换显示的图片
function changeImage() {
  // 隐藏当前显示的图片
  images[currentIndex].style.display = 'none';
  // 计算下一张要显示的图片的索引值
  currentIndex = (currentIndex + 1) % images.length;
  // 显示下一张图片
  images[currentIndex].style.display = 'block';
  // 2秒后再次切换图片
  setTimeout(changeImage, 2000);
}
//点击切换下一个图片
function nextImage(){
  var next = (currentIndex+1)%images.length;
  images[currentIndex].style.display = 'none';
  images[next].style.display = 'block';
}
//点击切换上一个图片
function lastImage(){
  var last = (currentIndex-1)%images.length;
  images[currentIndex].style.display = 'none';
  images[last].style.display = 'block';
}
function openLoginForm() {
  document.getElementById("loginForm").style.display = "block";
}

function closeLoginForm() {
  document.getElementById("loginForm").style.display = "none";
}

function openRegisterForm() {
  document.getElementById("registerForm").style.display = "block";
}

function closeRegisterForm() {
  document.getElementById("registerForm").style.display = "none";
}

function addCSS(){
  var link = document.createElement('link');
  link.rel = 'stylesheet';
  link.type = 'text/css';
  link.href = 'CSS/index.css';
  document.head.appendChild(link);
}

/*回到顶部*/
function backTop() {
  var timer  = null;
  box.onclick = function(){
    cancelAnimationFrame(timer);
    //获取当前毫秒数
    var startTime = +new Date();
    //获取当前页面的滚动高度
    var b = document.body.scrollTop || document.documentElement.scrollTop;
    var d = 500;
    var c = b;
    timer = requestAnimationFrame(function func(){
      var t = d - Math.max(0,startTime - (+new Date()) + d);
      document.documentElement.scrollTop = document.body.scrollTop = t * (-c) / d + b;
      timer = requestAnimationFrame(func);
      if(t == d){
        cancelAnimationFrame(timer);
      }
    });
  }
}